/*
 * Copyright 2012 Gregor Schauer
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package at.schauer.gregor.dormancy.persister;

import at.schauer.gregor.dormancy.Dormancy;
import at.schauer.gregor.dormancy.container.Team;
import at.schauer.gregor.dormancy.entity.Employee;

import javax.annotation.Nonnull;
import javax.inject.Inject;
import java.util.List;
import java.util.Map;

/**
 * @author Gregor Schauer
 */
public class TeamPersister extends AbstractContainerPersister<Team> {
	@Inject
	public TeamPersister(Dormancy dormancy) {
		super(dormancy);
	}

	@Override
	public <T extends Team> T clone_(T dbObj, @Nonnull Map<Object, Object> tree) {
		List<Employee> clone = dormancy.clone_(dbObj.getEmployees(), tree);
		dbObj.setEmployees(clone);
		return dbObj;
	}

	@Override
	public <T extends Team> T merge_(T trObj, @Nonnull Map<Object, Object> tree) {
		List<Employee> merge = dormancy.merge_(trObj.getEmployees(), tree);
		trObj.setEmployees(merge);
		return trObj;
	}

	@Override
	public <T extends Team> T merge_(T trObj, T dbObj, @Nonnull Map<Object, Object> tree) {
		List<Employee> merge = dormancy.merge_(trObj.getEmployees(), dbObj.getEmployees(), tree);
		trObj.setEmployees(merge);
		return trObj;
	}

	@Nonnull
	@Override
	protected Team createContainer(@Nonnull Team container) {
		return new Team();
	}
}
